package DAO;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import DTO.DTO_Local;
import Entities.Entity_Empleado;
import Entities.Entity_Local;
import Entities.Entity_Mesa;
import Hibernate.HibernateUtil;

public class DAO_Local {
		
		private static DAO_Local instancia = null;
		private static SessionFactory sf = null;

		public static DAO_Local getInstancia(){
			if(instancia == null){
				sf = HibernateUtil.getSessionFactory();
				instancia = new DAO_Local();
			} 
			return instancia;
		}
		
		public List<DTO_Local> getLocales(){
			Session session = sf.openSession();		
			String consulta = "Select l from Entity_Local l";
			Query q = session.createQuery(consulta);
			
			
			List<Entity_Local> locales = q.list();
			
			List<DTO_Local> locasDTO = new ArrayList<DTO_Local>();

			for(Entity_Local l: locales){
				DTO_Local lo = new DTO_Local();
				/*
				 * Convertir la mesa entity a mesa dto para devolver el array de dtos
				 */
				locasDTO.add(lo);
			}
						
			return locasDTO;
		}
		
		public void updateLocal(DTO_Local mesa){
			Entity_Local aux = new Entity_Local();
			/*
			 * convierto la mesa dto que me pasaron por parametro a la entity
			*/
			/*Abro sesion y grabo el objeto*/
			Session session = sf.openSession();
			session.beginTransaction();
			session.persist(aux);
			session.flush();
			session.getTransaction().commit();
			session.close();
		}
		

		
	
}
